<!DOCTYPE html>
<html>
<body>

<h2>简易计算器</h2>

<input type="text" id="txtDisplay" size="20"><br>

<input type="button" value="1" onclick="add('1')">
<input type="button" value="2" onclick="add('2')">
<input type="button" value="3" onclick="add('3')"><input type="button" value="+" onclick="add('+')"><br>


<input type="button" value="4" onclick="add('4')">
<input type="button" value="5" onclick="add('5')">
<input type="button" value="6" onclick="add('6')"><input type="button" value="-" onclick="add('-')"><br>

<input type="button" value="7" onclick="add('7')">
<input type="button" value="8" onclick="add('8')">
<input type="button" value="9" onclick="add('9')"><input type="button" value="*" onclick="add('*')"><br>


<input type="button" value="=" onclick="calculate()"><br>




<script>
function add(num) {
  var display = document.getElementById('txtDisplay');
  display.value += num;
}

function clear() {
  var display = document.getElementById('txtDisplay');
  display.value = '';
}

function calculate() {
  var display = document.getElementById('txtDisplay');
  var value = parseFloat(display.value);
  display.value = eval(display.value);
}
</script>

</body>
</html>